package com.guyj.baseapp.demo.progress;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;

import com.guyj.baseapp.R;
import com.guyj.common.base.BaseActivity;
import com.guyj.common.views.EasyProgressBar;

import butterknife.Bind;

/**
 * Created by Bada on 2016/10/10.
 */
public class EasyProgressActivity extends BaseActivity {
    private static final int WHAT_UPDATE = 1;
    @Bind(R.id.pb_main_demo1)
    EasyProgressBar pbMainDemo1;
    @Bind(R.id.pb_main_demo2)
    EasyProgressBar pbMainDemo2;
    @Bind(R.id.pb_main_demo3)
    EasyProgressBar pbMainDemo3;
    @Bind(R.id.pb_main_demo4)
    EasyProgressBar pbMainDemo4;
    @Bind(R.id.pb_main_demo5)
    EasyProgressBar pbMainDemo5;
    @Bind(R.id.pb_main_demo6)
    EasyProgressBar pbMainDemo6;
    @Bind(R.id.pb_main_demo7)
    EasyProgressBar pbMainDemo7;
    @Bind(R.id.progressBar)
    ProgressBar progressBar;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            int progress = pbMainDemo1.getProgress();
            progress++;
            if (progress < pbMainDemo1.getMax()) {
                sendEmptyMessageDelayed(WHAT_UPDATE, 100);
            } else if (progress == pbMainDemo1.getMax()) {
                sendEmptyMessageDelayed(WHAT_UPDATE, 2000);
            } else {
                progress = 0;
                sendEmptyMessageDelayed(WHAT_UPDATE, 100);
            }

            pbMainDemo1.setProgress(progress);
            pbMainDemo2.setProgress(progress);
            pbMainDemo3.setProgress(progress);
            pbMainDemo4.setProgress(progress);
            pbMainDemo5.setProgress(progress);
            pbMainDemo6.setProgress(progress);
            pbMainDemo7.setProgress(progress);
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacksAndMessages(null);
    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_easy_progress;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setBack();
        setTitle("EasyProgress");
    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        mHandler.sendEmptyMessageDelayed(WHAT_UPDATE, 400);
    }

}
